package com.yixing.tech.entity.service;

import com.yixing.tech.common.base.BusinessException;
import com.yixing.tech.common.base.ConditionsVO;
import com.yixing.tech.common.base.Page;
import com.yixing.tech.common.base.PageRow;
import com.yixing.tech.common.vo.s3.UserVO;
import com.yixing.tech.common.vo.s5.EntitySchema;
import com.yixing.tech.entity.entity.CustomActionParam;
import com.yixing.tech.entity.entity.GroupParam;
import com.yixing.tech.entity.po.EntityData;
import org.bson.Document;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yixing tech
 * at 2022/04/08
 * describe：
 */
public interface EntityBaseService {

    /**
     * 获取对象导入模板
     *
     * @param templateId
     * @throws BusinessException
     */
    void getImportTemplate(HttpServletResponse response, String templateId,String attrCode, UserVO userVO) throws BusinessException;

    /**
     * 插入实体
     *
     * @param templateId
     * @param entity
     * @throws BusinessException
     */
    String insetEntity(String templateId, EntityData entity) throws BusinessException;
    /**
     * 插入实体
     *
     * @param templateId
     * @param entity
     * @throws BusinessException
     */
    String insetEntity(String templateId, EntityData entity, boolean isCheck) throws BusinessException;
    /**
     * 插入实体
     *
     * @param templateId
     * @param entitys
     * @throws BusinessException
     */
    void insetEntitys(String templateId, List<Map> entitys, UserVO loginUser) throws BusinessException;


    /**
     * 导入实体
     *
     * @param templateId
     * @param file
     * @throws BusinessException
     */
    void importEntity(String templateId, MultipartFile file, UserVO loginUser) throws Exception;

    /**
     * 导出实体
     *
     * @param templateId
     * @throws BusinessException
     */
    void exportEntity(HttpServletResponse response, String templateId, ConditionsVO condition, UserVO userVO) throws BusinessException;

    /**
     * 解析excel
     *
     * @param file
     * @param templateId
     * @return
     * @throws BusinessException
     */
    Object parseExcel(MultipartFile file, String templateId,String tenantId) throws Exception;

    /**
     * 解析excel
     *
     * @param file
     * @param templateId
     * @return
     * @throws BusinessException
     */
    Object parseSubExcel(MultipartFile file, String templateId, String attrName,String tenantId) throws Exception;

    /**
     * 删除实体
     *
     * @param templateId
     * @param entityId
     * @throws BusinessException
     */
    void removeEntity(String templateId, String entityId, String tenantId) throws BusinessException;
    /**
     * 批量删除实体
     *
     * @param templateId
     * @param entityIds
     * @throws BusinessException
     */
    void removeEntities(String templateId, List<String> entityIds) throws BusinessException;
    /**
     * 物理删除
     *
     * @param templateId
     * @param map
     * @throws BusinessException
     */
    void removeEntity(String templateId, Map<String, Object> map, String tenantId) throws BusinessException;

    /**
     * 获取实体
     *
     * @param templateId
     * @param entityId
     * @return
     * @throws BusinessException
     */
    Document getEntity(String templateId, String entityId, UserVO userVO, boolean forEdit) throws BusinessException;

    /**
     * 更新实体
     *
     * @param templateId
     * @param entity
     * @throws BusinessException
     */
    void updateEntity(String templateId, EntityData entity) throws BusinessException;

    /**
     * 更新实体
     *
     * @param templateId
     * @param entity
     * @throws BusinessException
     */
    void updateEntityAsync(String templateId, EntityData entity) throws BusinessException;

    /**
     * 更新实体
     *
     * @param templateId
     * @param entity
     * @throws BusinessException
     */
    void updateEntity(String templateId, List<ConditionsVO.Condition> cond, Map entity) throws BusinessException;

    /**
     * 作废
     *
     * @param templateId
     * @param entityId
     * @throws BusinessException
     */
    void disableEntity(String templateId, String entityId, LinkedHashMap updateMap) throws BusinessException;

    /**
     * 执行对象行为
     *
     * @throws BusinessException
     */
    void excAction(CustomActionParam param) throws BusinessException;

    /**
     * 分页列表
     *
     * @param pageRow
     * @return
     */
    Page listPage(PageRow<ConditionsVO> pageRow, String templateId, UserVO userVO) throws BusinessException;
    Page listPageRedundancy(PageRow<ConditionsVO> pageRow, String templateId, UserVO userVO,boolean isRedundancy) throws BusinessException;
    /**
     * 列表
     *
     * @return
     */
    List<Document> list(ConditionsVO conditions, String templateId, UserVO userVO) throws BusinessException;

    EntitySchema queryByTableId(String id, UserVO user)throws BusinessException;

    default EntitySchema queryByTableId(String id)throws BusinessException {
        return queryByTableId(id, null);
    }

    Long count(ConditionsVO conditions, String templateId) throws BusinessException;

    /**
     * 列表树
     *
     * @return
     */
    List<Document> tree(String templateId, ConditionsVO condition, UserVO userVO) throws BusinessException;

    /**
     * 实体分组
     *
     * @throws BusinessException
     */
    void group(GroupParam param) throws BusinessException;
     /**
     * 合计
     * @param conditions
     * @param templateId
     * @param attr
     * @param userVO
     * @return
     * @throws BusinessException
     */
    Object summation(ConditionsVO conditions, String templateId, String attr,UserVO userVO)throws BusinessException;


     /**
     * 属性合计
     * @param conditions
     * @param templateId
     * @param attr
     * @param userVO
     * @return
     * @throws BusinessException
     */
    public Object count(ConditionsVO conditions, String templateId, String attr, UserVO userVO) throws BusinessException;
}
